package com.daocao.jy.view;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.daocao.jy.R;
import com.daocao.jy.activity.OilCardAddActivity;
import com.daocao.jy.adapter.OilChangeAdapter;
import com.daocao.jy.api.model.OilcardListModel;
import com.daocao.jy.util.Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by xsooy-pc on 2017/4/24.
 */

public class OilChangeDialog extends Dialog {


    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.layout_add_new)
    RelativeLayout layoutAddNew;
    private Context context;
    private OilChangeAdapter adapter;

    public OilChangeDialog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public OilChangeDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_change_oil);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = (int) (Util.getDisplayMetrics(context).widthPixels * 0.85);
        mWindow.setAttributes(lp);

        adapter = new OilChangeAdapter(context);
        adapter.setOnChooseListener(new OilChangeAdapter.OnChooseListener() {
            @Override
            public void onClick(String id, String ctype, String card_number) {
                if (listener != null) {
                    listener.confirm(id, ctype, card_number);
                }
                dismiss();
            }
        });
        list.setAdapter(adapter);
    }


    public void setData(List<OilcardListModel.DatasBean> data) {
        adapter.update(data);
    }


    private DialogDefaultClickListener listener;

    public void setDialogClickListener(DialogDefaultClickListener listener) {
        this.listener = listener;
    }

    @OnClick(R.id.layout_add_new)
    public void onViewClicked() {
        Util.startActivity(context, OilCardAddActivity.class);
        dismiss();
    }


    public interface DialogDefaultClickListener {
        public abstract void confirm(String id, String ctype, String card_number);

        public abstract void cancel();
    }
}
